@extends('backend.layouts.base')
@section('title', '网站信息设置')
@section('content')
    <div class="all">
        <div id="app" v-cloak>
            <el-form ref="form" :model="form" :rules="rules" label-width="15%">
                <div class="vue-head">
                    <div class="vue-main-title">
                        <div class="vue-main-title-left"></div>
                        <div class="vue-main-title-content">网站信息设置</div>
                    </div>
                    <div class="vue-main-form">
                        <el-form-item label="网站名称" prop="site_name">
                            <el-input v-model="form.site_name" ref="site_name"></el-input>
                        </el-form-item>
                    </div>
                    <el-form-item label="site_logo" prop="site_logo">
                        <div class="upload-box" @click="openUpload('site_logo')" v-if="!form.site_logo">
                            <i class="el-icon-plus" style="font-size:32px"></i>
                        </div>
                        <div @click="openUpload('site_logo')" class="upload-boxed" v-if="form.site_logo">
                            <img :src="form.site_logo" alt="" style="width:150px;height:150px;border-radius: 5px;cursor: pointer;">
                            <div class="upload-boxed-text">点击重新上传</div>
                        </div>
                    </el-form-item>
                    <el-form-item label="favorite icon" prop="title_icon">
                        <div class="upload-box" @click="openUpload('title_icon')" v-if="!form.title_icon">
                            <i class="el-icon-plus" style="font-size:32px"></i>
                        </div>
                        <div @click="openUpload('title_icon')" class="upload-boxed" v-if="form.title_icon">
                            <img :src="form.title_icon" alt="" style="width:150px;height:150px;border-radius: 5px;cursor: pointer;">
                            <div class="upload-boxed-text">点击重新上传</div>
                            <div class="tip">显示在浏览器标题的图标</div>
                        </div>
                    </el-form-item>
                    <el-form-item label="登录页广告" prop="advertisement">
                        <div class="upload-box" @click="openUpload('advertisement')" v-if="!form.advertisement">
                            <i class="el-icon-plus" style="font-size:32px"></i>
                        </div>
                        <div @click="openUpload('advertisement')" class="upload-boxed" v-if="form.advertisement">
                            <img :src="form.advertisement" alt="" style="width:150px;height:150px;border-radius: 5px;cursor: pointer;">
                            <div class="upload-boxed-text">点击重新上传</div>
                            <div class="tip">请上传750*365px方形图片</div>
                        </div>
                    </el-form-item>
                    <el-form-item label="底部信息" prop="information">
                        <tinymceee v-model="form.information"></tinymceee>
                    </el-form-item>
                    <div class="vue-main-form">
                        <el-form-item label="公司名称" prop="company_name">
                            <el-input v-model="form.company_name" ref="company_name"></el-input>
                        </el-form-item>
                    </div>
                    <div class="vue-main-form">
                        <el-form-item label="ICP备案" prop="icp_no">
                            <el-input v-model="form.icp_no" ref="icp_no"></el-input>
                        </el-form-item>
                    </div>
                    <div class="vue-main-form">
                        <el-form-item label="公安备案" prop="police_no">
                            <el-input v-model="form.police_no" ref="police_no"></el-input>
                        </el-form-item>
                    </div>
                    <div class="vue-main-form">
                        <el-form-item label="SEO标题" prop="seo_title">
                            <el-input v-model="form.seo_title" ref="seo_title"></el-input>
                        </el-form-item>
                    </div>
                    <div class="vue-main-form">
                        <el-form-item label="SEO关键词" prop="seo_keywords">
                            <el-input v-model="form.seo_keywords" ref="seo_keywords"></el-input>
                        </el-form-item>
                    </div>
                    <div class="vue-main-form">
                        <el-form-item label="SEO描述" prop="seo_description">
                            <el-input v-model="form.seo_description" :rows="5" type="textarea" ref="seo_description"></el-input>
                        </el-form-item>
                    </div>
                    <div class="vue-main-form">
                        <el-form-item label="网站统计代码" prop="statistics_code">
                            <el-input v-model="form.statistics_code" :rows="5" type="textarea" ref="statistics_code"></el-input>
                        </el-form-item>
                    </div>
                </div>
            </el-form>
            <div class="vue-page">
                <div class="vue-center">
                    <el-button type="primary" @click="submitForm('form')">提交</el-button>
                    <el-button @click="goBack">返回</el-button>
                </div>
            </div>
            <upload-img :upload-show="uploadShow" :name="chooseImgName" @replace="changeProp" @sure="sureImg"></upload-img>
        </div>
    </div>
    <script src="/static/libs/tinymce4.7.5/tinymce.min.js"></script>
    @include('backend.public.tinymceee')
    @include('backend.public.uploadImg')
    <script>
        var app = new Vue({
            el:"#app",
            delimiters: ['[[', ']]'],
            name: 'settingSite',
            data() {
                return{
                    form:{
                        site_name:'',
                        site_logo:'',
                        title_icon:'',
                        advertisement:'',
                        information:'',
                        company_name:'',
                        icp_no:'',
                        police_no:'',
                        seo_title:'',
                        seo_keywords:'',
                        seo_description:'',
                        statistics_code:''
                    },
                    rules:{
                    },
                    uploadShow:false,
                    chooseImgName:''
                }
            },
            created() {
            },
            mounted() {
                this.getData();
            },
            methods: {
                getData() {
                    let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
                    this.$http.post('{!! absolute_admin_url('sys.setting.siteInfo') !!}',{}).then(function (response) {
                            if (response.data.result){
                                this.form = {
                                    ...response.data.data,
                                };
                            }
                            else {
                                this.$message({message: response.data.msg,type: 'error'});
                            }
                            loading.close();
                        },function (response) {
                            this.$message({message: response.data.msg,type: 'error'});
                            loading.close();
                        }
                    );
                },
                submitForm(formName) {
                    console.log(this.form)
                    let that = this;
                    let json = {
                        site_name:this.form.site_name,
                        site_logo:this.form.site_logo,
                        title_icon:this.form.title_icon,
                        advertisement:this.form.advertisement,
                        information:this.form.information,
                        company_name:this.form.company_name,
                        icp_no:this.form.icp_no,
                        police_no:this.form.police_no,
                        seo_title:this.form.seo_title,
                        seo_keywords:this.form.seo_keywords,
                        seo_description:this.form.seo_description,
                        statistics_code:this.form.statistics_code
                    };

                    this.$refs[formName].validate((valid) => {
                        if (valid) {
                            let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
                            this.$http.post('{!! absolute_admin_url('sys.setting.siteSave') !!}',{setting:json}).then(response => {
                                if (response.data.result) {
                                    this.$message({type: 'success',message: '操作成功!'});
                                } else {
                                    this.$message({message: response.data.msg,type: 'error'});
                                }
                                loading.close();
                            },response => {
                                this.$message({message: response.data.msg,type: 'error'});
                                loading.close();
                            });
                        }
                        else {
                            console.log('error submit!!');
                            return false;
                        }
                    });
                },

                goBack() {
                    history.go(-1)
                },
                openUpload(str) {
                    this.chooseImgName = str;
                    this.uploadShow = true;
                },
                changeProp(val) {
                    if(val == true) {
                        this.uploadShow = false;
                    }
                    else {
                        this.uploadShow = true;
                    }
                },
                sureImg(name,image,image_url) {
                    this.form[name] = image_url;
                },
                clearImg(str) {
                    this.form[str] = "";
                    this.$forceUpdate();
                }
            },
        })

    </script>
@endsection
